class Solution {
public:
    string multiply(string num1, string num2) {
        int n1 = num1.size(), n2 = num2.size();
        vector<int> tmp(n1 + n2 - 1);
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());
 
        for(int i = 0; i < n1; ++i)
        {
            for(int j = 0; j < n2; ++j)
            {
                tmp[i+j] += (num1[i] - '0') * (num2[j] - '0');
            }
        }
        string ret = "";
        int carry = 0;
        for(auto& e : tmp)
        {
            cout << e << " ";
            ret += ((e + carry) % 10 + '0');
            carry = (e + carry) / 10; 
        }
        if(carry)
            ret += (carry + '0');
 
        while(ret.size() > 1 && ret.back() == '0') 
            ret.pop_back(); // 处理前导0
 
        reverse(ret.begin(), ret.end());
        return ret;
    }
};